package org.qphoto;

import java.util.List;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ThumbnailAdapter extends BaseAdapter {

	private Activity context   = null;
	private List<String> list = null;
	
	public ThumbnailAdapter(Activity context,List<String> list)
	{
		this.context = context;
		this.list    = list; 
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		/*
		ImageView thumbnail = null;
		if (convertView == null) {
			thumbnail   = new ImageView(context);
			thumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
			
			String thumbnailuri = list.get(position);
			Bitmap picimage     = BitmapFactory.decodeFile(thumbnailuri);
			if ( picimage != null)
			{
				thumbnail.setImageBitmap(picimage);
			}
			
		} else {
			thumbnail = (ImageView) convertView;
		}
		//thumbnail.setPadding(5, 5, 5, 5);
		return thumbnail;
		*/
		
		LinearLayout layout = new LinearLayout(context);
		if (convertView    == null) {
			ImageView thumbnail   = new ImageView(context);
			thumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
			
			String thumbnailuri = list.get(position);
			Bitmap picimage     = BitmapFactory.decodeFile(thumbnailuri);
			if ( picimage != null)
			{
				thumbnail.setImageBitmap(picimage);
			}
			thumbnail.setBackgroundColor(Color.rgb(255, 180, 0));
			
			int hpadding = 4 * picimage.getHeight() / picimage.getWidth() + 2;
			layout.addView(thumbnail);
			layout.setPadding(4,hpadding,4,hpadding);
		} else {
			layout = (LinearLayout) convertView;
		}
		//thumbnail.setPadding(5, 5, 5, 5);
		return layout;
	}

}
